<?php

include_once 'Answer_Patterns.php';
include_once 'Mount_DOM_tree.php';

class Refactoring_Add_Tittle extends Answer_Patterns {

   public function start($domDocument) {
      $result = "";
      $mount_tree = new Mount_DOM_tree();

      $search = $domDocument->getElementsByTagName('input');

      foreach ($search as $f) {
         if (empty($f->getAttribute('title')) && ($f->getAttribute('type') == "submit" || $f->getAttribute('type') == "reset")) {
            $answer = ' title="descricao botão"';
            $result .= parent::elementAnswerPatterns("&LT;$f->nodeName&GT;", $f->getLineNo(), $answer, "Adicione o atributo ", "sem o atributo <em>title</em>");
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $mount_tree->structHTMLElementRefactory($f, 1, 0, "$f->nodeName", 1, $answer));
         }
      }
      
      $search = $domDocument->getElementsByTagName('a');

      foreach ($search as $f) {
         if (empty($f->getAttribute('title'))) {
            $answer = ' title="descricao link"';
            $result .= parent::elementAnswerPatterns("&LT;$f->nodeName&GT;", $f->getLineNo(), $answer, "Adicione o atributo ", "sem o atributo <em>title</em>");
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $mount_tree->structHTMLElementRefactory($f, 1, 0, "$f->nodeName", 1, $answer));
         }
      }
      
      $search = $domDocument->getElementsByTagName('button');

      foreach ($search as $f) {
         if (empty($f->getAttribute('title'))) {
            $answer = ' title="descricao botão"';
            $result .= parent::elementAnswerPatterns("&LT;$f->nodeName&GT;", $f->getLineNo(), $answer, "Adicione o atributo ", "sem o atributo <em>title</em>");
            $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $mount_tree->structHTMLElementRefactory($f, 1, 0, "$f->nodeName", 1, $answer));
         }
      }
      if (!empty($result)) {
         $result = parent::titleAnswerPatterns("Adicionar atributo <em>title</em> para Botões e Links") . $result;
      }
      return $result;
   }

}

?>